package com.myhost;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ProgressBarBroadcastReceiver extends BroadcastReceiver {

	private ProgressBar progressBar;
	private TextView tv;
	private String text;
	private int position;
	private AlertDialog dialog;

	public ProgressBarBroadcastReceiver(Context context, View layout) {
		super();
		progressBar = (ProgressBar) layout.findViewById(R.id.progressBar);
		tv = (TextView) layout.findViewById(R.id.progressBarTv);
		progressBar.setMax(100);
		dialog = new AlertDialog.Builder(context).setView(layout).create();
		dialog.show();
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		text = intent.getStringExtra("text");
		position = intent.getIntExtra("progress", 0);
//		com.myhost.utils.Log.i("BROADCAST" + text + "    i = " + position	);
		if (dialog.isShowing()) {
			if (position == 0) {
				tv.setText(text);
			}
			progressBar.setProgress(position);
		}
	}

}
